package com.lhy.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lhy.vip.domain.Evaluation;
import com.lhy.vip.service.EvaluationService;
import com.lhy.vip.mapper.EvaluationMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author lhy
* @description 针对表【evaluation】的数据库操作Service实现
* @createDate 2024-07-29 16:10:40
*/
@Service
public class EvaluationServiceImpl implements EvaluationService{
    @Autowired
    private EvaluationMapper iEvaluationMapper;

    @Override
    public List<Evaluation> selectAll() {
        LambdaQueryWrapper <Evaluation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Evaluation::getIsDelete,0);
        return iEvaluationMapper.selectList(lqw);
    }


    @Override
    public List<Evaluation> selectList(Evaluation iEvaluation) {
        LambdaQueryWrapper <Evaluation> lqw = this.lqw(iEvaluation);
        return iEvaluationMapper.selectList(lqw);
    }

    @Override
    public Integer insert(Evaluation iEvaluation) {
        return iEvaluationMapper.insert(iEvaluation);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                Evaluation iEvaluation = new Evaluation();
                iEvaluation.setId(Long.parseLong(id));
                iEvaluation.setIsDelete(1);
                iEvaluationMapper.updateById(iEvaluation);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(Evaluation iEvaluation) {
        return iEvaluationMapper.updateById(iEvaluation);
    }

    @Override
    public Page<Evaluation> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Evaluation>)this.selectAll();
    }

    @Override
    public Page<Evaluation> pageList(Evaluation iEvaluation, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Evaluation>)this.selectList(iEvaluation);
    }

    public LambdaQueryWrapper lqw(Evaluation iEvaluation){
        LambdaQueryWrapper <Evaluation> lqw = new LambdaQueryWrapper<>();
        if (iEvaluation.getId() != null){
            lqw.eq(Evaluation::getId,iEvaluation.getId());
        }
        if (iEvaluation.getProduceName() != null){
            lqw.eq(Evaluation::getProduceName,iEvaluation.getProduceName());
        }
        if (iEvaluation.getVipName() != null){
            lqw.eq(Evaluation::getVipName,iEvaluation.getVipName());
        }
        if (iEvaluation.getEvaluate() != null){
            lqw.eq(Evaluation::getEvaluate,iEvaluation.getEvaluate());
        }
        if (iEvaluation.getCreateTime() != null){
            lqw.eq(Evaluation::getCreateTime,iEvaluation.getCreateTime());
        }
        if (iEvaluation.getStatus() != null){
            lqw.eq(Evaluation::getStatus,iEvaluation.getStatus());
        }
        if (iEvaluation.getIsDelete() != null){
            lqw.eq(Evaluation::getIsDelete,iEvaluation.getIsDelete());
        }
        if (iEvaluation.getWlEvaluate() != null){
            lqw.eq(Evaluation::getWlEvaluate,iEvaluation.getWlEvaluate());
        }
        if (iEvaluation.getFwEvaluate() != null){
            lqw.eq(Evaluation::getFwEvaluate,iEvaluation.getFwEvaluate());
        }
        if (iEvaluation.getMsEvaluate() != null){
            lqw.eq(Evaluation::getMsEvaluate,iEvaluation.getMsEvaluate());
        }
        return lqw;
    }
}




